其他
ifconfig已淘汰,ip登场(iproute工具包)
教程每周二、四、六更新
Name : net-tools
Version : 2.0
......
Description :
The net-tools package contains basic networking tools,
including ifconfig, netstat, route, and others.
Most of them are obsolete. For replacement check iproute package.
[root@m01 ~]# rpm -ql iproute
/etc/iproute2
/etc/iproute2/bpf_pinning
/etc/iproute2/ematch_map
/etc/iproute2/group
/etc/iproute2/nl_protos
/etc/iproute2/rt_dsfield
/etc/iproute2/rt_protos
/etc/iproute2/rt_realms
/etc/iproute2/rt_scopes
/etc/iproute2/rt_tables
/etc/sysconfig/cbq
/etc/sysconfig/cbq/avpkt
/etc/sysconfig/cbq/cbq-0000.example
/usr/lib64/tc
/usr/lib64/tc/experimental.dist
/usr/lib64/tc/m_ipt.so
/usr/lib64/tc/m_xt.so
/usr/lib64/tc/normal.dist
/usr/lib64/tc/pareto.dist
/usr/lib64/tc/paretonormal.dist
/usr/sbin/arpd
/usr/sbin/bridge
/usr/sbin/cbq
/usr/sbin/ctstat
/usr/sbin/devlink
/usr/sbin/genl
/usr/sbin/ifcfg
/usr/sbin/ifstat
/usr/sbin/ip
/usr/sbin/lnstat
/usr/sbin/nstat
/usr/sbin/rdma
/usr/sbin/routef
/usr/sbin/routel
/usr/sbin/rtacct
/usr/sbin/rtmon
/usr/sbin/rtpr
/usr/sbin/rtstat
/usr/sbin/ss
/usr/sbin/tc
......
语法
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
where OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |
vrf }
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec |
-f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
-4 | -6 | -I | -D | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } | -br[ief] |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
-rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}
OPTIONS
-s 显示更详细的信息
-h 显示数字时,以更方便阅读的方式显示,即自动显示为KB、MB、GB等形式
-f 强制使用指定的协议族
-r 显示主机时,不适用IP地址,而是使用主机的域名
-4 | -6 使用ipv4协议还是使用ipv6协议
OBJECT
address IP地址信息
neighbour 邻居表。用来管理ARP或NDISC缓存项
route 路由表。【实现原来route命令的功能】
rule 管理路由策略
tunnel IP隧道
COMMAND
delete
show(list)
argument
ip address
[root@m01 ~]# ip addr help
Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]
[ CONFFLAG-LIST ]
ip address del IFADDR dev IFNAME [mngtmpaddr]
ip address {save|flush} [ dev IFNAME ] [ scope SCOPE-ID ]
[ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]
ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]
[ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]
[ label LABEL ] [up] [ vrf NAME ] ]
ip address {showdump|restore}
ip addr show # 显示网卡IP信息
ip addr add 192.168.20.1/24 dev eth0 # 设置eth0网卡IP地址192.168.0.1
ip addr del 192.168.20.1/24 dev eth0 # 删除eth0网卡IP地址
ip a show dev ens33 # 查看某个特定网卡的信息
ip link
Usage: ip link add [link DEV] [ name ] NAME
[ txqueuelen PACKETS ]
[ address LLADDR ]
[ broadcast LLADDR ]
type TYPE [ ARGS ]
ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]
ip link set { DEVICE | dev DEVICE | group DEVGROUP }
[ { up | down } ]
[ dynamic { on | off } ]
[ promisc { on | off } ]
[ broadcast LLADDR ]
[ txqueuelen PACKETS ]
[ mtu MTU ]
......
ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]
ip link xstats type TYPE [ ARGS ]
ip link afstats [ dev DEVICE ]
ip link help [ TYPE ]
TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
bridge | bond | team | ipoib | ip6tnl | ipip | sit | vxlan |
gre | gretap | ip6gre | ip6gretap | vti | nlmon | team_slave |
bond_slave | ipvlan | geneve | bridge_slave | vrf | macsec }
broadcast表示该网络设备可以将数据报传送给子网内的所有主机; dynamic 表示该网络设备可以动态的建立和删除。 promisc表示网络设备处于混杂模式,这时该设备将进行监听并将监听到的数据传递给内核,即使这些数据不是发送给该主机的。通常用于网络探测。
ip link set eth0 up # 开启网卡eth0,类似以前的ifup eth0
ip link set eth0 down # 关闭网卡eth0,类似以前的ifdown eth0
ip link set eth0 promisc on # 开启网卡的混合模式
ip link set eth0 promisc offi # 关闭网卡的混个模式
ip link set eth0 txqueuelen 1200 # 设置网卡队列长度
ip link set eth0 mtu 1400 # 设置网卡最大传输单元
ip neighbour
Usage: ip neigh { add | del | change | replace }
{ ADDR [ lladdr LLADDR ] [ nud STATE ] | proxy ADDR } [ dev DEV ]
ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]
[ vrf NAME ]
STATE := { permanent | noarp | stale | reachable | none |
incomplete | delay | probe | failed }
ip neigh # 查看当前邻居信息
ip neigh add 192.168.10.3 lladdr 0:0:0:0:0:1 dev ens32 nud perm # 永久添加一个邻居信息
ip neigh del 192.168.10.100 dev ens34 # 删除添加的信息
ip route
ip route list # 查看路由信息
ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 设置192.168.4.0网段的网关为192.168.0.254,数据走eth0接口
ip route del 192.168.4.0/24 # 删除192.168.4.0网段的网关
ip route del default # 删除默认路由
ip route delete 192.168.1.0/24 dev eth0 # 删除路由
Usage: ip route { list | flush } SELECTOR
ip route save SELECTOR
ip route restore
ip route showdump
ip route get ADDRESS [ from ADDRESS iif STRING ]
[ oif STRING ] [ tos TOS ]
[ mark NUMBER ] [ vrf NAME ]
[ uid NUMBER ]
ip route { add | del | change | append | replace } ROUTE
ip route restore < tablesave # 用刚才保存的路由表来恢复原有的路由表
ip rule
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
[root@m01 ~]# cat /etc/iproute2/rt_tables |grep -v "^#"
255 local
254 main
253 default
0 unspec
Usage: ip rule { add | del } SELECTOR ACTION
ip rule { flush | save | restore }
ip rule [ list [ SELECTOR ]]
SELECTOR := [ not ] [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK[/MASK] ]
[ iif STRING ] [ oif STRING ] [ pref NUMBER ] [ l3mdev ]
[ uidrange NUMBER-NUMBER ]
ACTION := [ table TABLE_ID ]
[ nat ADDRESS ]
[ realms [SRCREALM/]DSTREALM ]
[ goto NUMBER ]
SUPPRESSOR
SUPPRESSOR := [ suppress_prefixlength NUMBER ]
[ suppress_ifgroup DEVGROUP ]
TABLE_ID := [ local | main | default | NUMBER ]
To 目的地址(这里是选择规则时使用,查找路由表时也使用)
Tos IP包头的TOS(type of sevice)域
Dev 物理接口
Fwmark 防火墙参数
Nat 透明网关
Action prohibit 丢弃该包,并发送 COMM.ADM.PROHIITED的ICMP信息
Reject 单纯丢弃该包
Unreachable 丢弃该包, 并发送 NET UNREACHABLE的ICMP信息
指定优先级 第一条命令将向规则链增加一条规则,规则匹配的对象是所有的数据包,动作是选用路由表1的路由,这条规则的优先级是32000. 第二条命令将向规则链增加一条规则,规则匹配的对象是IP为172.16.8.12, tos等于0x10的包,使用路由表2,这条规则的优先级是32001,动作是丢弃。
[root@m01 ~]# ip rule add from 172.16.8.12/32 tos 0x10 table 2 pref 32001 prohibit
[root@m01 ~]# ip rule
0: from all lookup local
32000: from all lookup 1
32001: from 172.16.8.12 tos lowdelay lookup 2 prohibit
32766: from all lookup main
32767: from all lookup default
[root@m01 ~]# ip rule
0: from all lookup local
31999: from 171.13.12.23 lookup 200
32000: from all lookup 1
32001: from 172.16.8.12 tos lowdelay lookup 2 prohibit
32766: from all lookup main
32767: from all lookup default
ip rule add from 192.168.10.100 lookup 200
Linux 网络状态工具 ss 命令详解
这次终于搞明白VLAN技术了
我是如何用10分钟理解Kubernetes的
除每周二、四、六定期更新的《Linux云计算一站式教程》以外,其余时间雷哥会推送一些工作中遇到的小知识、实战经验总结的文章。后续都会收录在“实战经验”合集中。